package com.abc.springboot.service.impl;

import com.abc.springboot.mapper.UserMapper;
import com.abc.springboot.pojo.User;
import com.abc.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> queryUsers() {
        return userMapper.selectUsers();
    }

    @Override
    public User queryUserByAccount(long account) {
        return userMapper.selectUserByAccount(account);
    }

    @Override
    public void addUser(User user) {
        userMapper.insertUser(user);
    }

    @Override
    public int loginVerify(long account, String passwordFromWeb) {
        User user=userMapper.selectUserByAccount(account);
        if(user==null){
            return 400;
        }
        String passwordFromDatabase=user.getPassword();
        //String passwordFromDatabase=userService.queryUserByAccount(account).getPassword();
        if(passwordFromDatabase.equals(passwordFromWeb)){
            //密码校验成功
            return 200;
        }
        //密码不匹配
        return 201;
    }

    @Override
    public int updateUserByPhonenumber(User user) {
        return userMapper.updateUserByAccount(user);
    }

    @Override
    public int updateUserPassword(User user) {
        return userMapper.updateUserPassword(user);
    }


}
